﻿using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

using Microsoft.WowAddonStudio.Lua.Model;

namespace Microsoft.WowAddonStudio.Lua.Support
{
    public class XmlDocumentationSerializer : XmlSerializer
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlDocumentationSerializer"/> class.
        /// </summary>
        public XmlDocumentationSerializer()
            : base(typeof(Documentation))
        {
        }

        /// <summary>
        /// Deserializes the XML documentation at the specified path.
        /// </summary>
        /// <param name="xmlDocumentationPath">Path of the XML documentation.</param>
        /// <returns>An instance of the <see cref="Documentation"/> class.</returns>
        public Documentation Deserialize(string xmlDocumentationPath)
        {
            if (xmlDocumentationPath == null)
                throw new ArgumentNullException("xmlDocumentationPath");

            using (var xmlReader = XmlReader.Create(xmlDocumentationPath))
            {
                return (Documentation)this.Deserialize(xmlReader);
            }
        }

        /// <summary>
        /// Deserializes the XML documentation at the specified path.
        /// </summary>
        /// <param name="xmlDocumentationStream">Stream of the XML documentation.</param>
        /// <returns>An instance of the <see cref="Documentation"/> class.</returns>
        public new Documentation Deserialize(Stream xmlDocumentationStream)
        {
            if (xmlDocumentationStream == null)
                throw new ArgumentNullException("xmlDocumentationStream");

            using (var xmlReader = XmlReader.Create(xmlDocumentationStream))
            {
                return (Documentation)this.Deserialize(xmlReader);
            }
        }
    }
}
